﻿#include "yanse.h"

//yanse::yanse()
//{
//    sock = -1;
//}

yanse::yanse(int port)
{
         this->clt_port = port;
        sock = socket(AF_INET,SOCK_DGRAM,0);
        client_addr.sin_family = AF_INET;
        client_addr.sin_port = htonl(port);
        client_addr.sin_addr.s_addr = 0;
        sockbind();
}


bool yanse::sockbind()
{
        if(bind(sock,(struct sockaddr*)&client_addr,sizeof(client_addr)) != 0)
        {
            close(sock);
            return -1;
        }
}

bool yanse::udp_send(char* ip,int port,char *buf)
{
    struct sockaddr_in aaa;
    aaa.sin_addr.s_addr= inet_addr(ip);
    aaa.sin_port=htonl(port);
    sendto(sock,buf,sizeof(buf),0,(struct sockaddr*)&aaa,sizeof(aaa));
}


bool yanse::recive()
{
    struct sockaddr_in addr;
    char buf[20];
    recvfrom(sock,buf,20,0,(struct sockaddr*)&addr,sizeof(addr));
}


